/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.messaging.inbox;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import nl.cloudfarming.client.messaging.Message;
import org.jdesktop.swingx.JXHeader;

/**
 *
 * @author Timon Veenstra
 */
public class MessageSummaryPanel extends JXHeader implements MouseListener {

    private final Message message;

    public MessageSummaryPanel(Message message) {
        super(message.getTitle().substring(0, (message.getTitle().length() > 50 ? 50 : message.getTitle().length()))
                , message.getMessageText().substring(0, (message.getMessageText().length() > 200 ? 200 : message.getMessageText().length()))
                , message.getImageIcon());
        this.message = message;
        if (message.getImageIcon() == null && message.getImage() != null) {
            setIcon(new ImageIcon(message.getImage()));
        }
        setIconPosition(IconPosition.LEFT);
        setPreferredSize(new Dimension(300, 50));
        addMouseListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() >= 2) {
            MessageDisplayFrame messagePopUp = new MessageDisplayFrame(message);
            messagePopUp.setVisible(true);
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }
}
